package com.zy.controller;

import com.zy.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author LittleDesire
 * @description
 * @date 2022-04-08 周五 10:14
 * @since 17
 */
@RestController
public class HomeController {
    @Autowired
    private JwtUtils jwtUtils;
    @RequestMapping
    public String index() {
        return "项目首页";
    }

    @RequestMapping("/asave")
    public Map<String, String> asave(@RequestHeader(value = "token", required = false, defaultValue = "") String token) {
        Map<String, String> map = new HashMap<>();
        if ("".equalsIgnoreCase(token)) {
            map.put("code","405");
            map.put("msg", "令牌无效");
        } else if (jwtUtils.verifyToken(token)) {
            map.put("code","200");
            map.put("msg", "欢迎登陆");
        }else {
            map.put("msg", "错误");
        }
        return map;
    }

    @RequestMapping("/adel")
    public Map<String, String> adel(HttpServletRequest req) {
        Map<String, String> map = new HashMap<>();
        String token = req.getHeader("token");
        if ("".equalsIgnoreCase(token)) {
            map.put("code","405");
            map.put("msg", "令牌无效");
        } else if (jwtUtils.verifyToken(token)) {
            map.put("code","200");
            map.put("msg", "欢迎登陆");
        }else {
            map.put("msg", "错误");
        }
        return map;
    }
}
